package ar.edu.itba.it.cg.grupo01.game.sound;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import ar.edu.itba.it.cg.grupo01.utils.Utils;

import com.jmex.audio.AudioSystem;
import com.jmex.audio.AudioTrack;

public enum PioneerSoundSystem {
	
	COLLISSION {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("collission.path");
		}
	},
	HONK {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("honk.path");
		}
	},
	
	ACCELERATION {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("acceleration.path");
		}
	},

	SMALLCHEER {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("smallcheer.path");
		}
	},
	
	LARGECHEER {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("largecheer.path");
		}
	},
	
	CARRESET {
		@Override
		public String getTrackPath() {
			return soundProperties.getProperty("carreset.path");
		}
	};

	private static Properties soundProperties;

	//Open sound properties file
	static{
		soundProperties= new Properties();
		try {
			soundProperties.load(new FileInputStream(new File(Utils.getResourceURL("properties/sound.properties").toURI())));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AudioTrack sound = null;
	
	public AudioTrack getTrack(boolean shouldLoop) {
		AudioTrack audioTrack = getTrack();
		audioTrack.setLooping(shouldLoop);

		return audioTrack;
	}


	public AudioTrack getTrack() {
		if(sound == null)
			sound = AudioSystem.getSystem().createAudioTrack(Utils.getResourceURL(getTrackPath()), false);
		
		return sound;
	}
	
	
	public abstract String getTrackPath();

}